package com.ruoyi.activity.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activity.domain.TbActivityConfig;
import com.ruoyi.activity.service.ITbActivityConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动设置Controller
 * 
 * @author jll
 * @date 2025-06-13
 */
@RestController
@RequestMapping("/ruoyi-activity/config")
public class TbActivityConfigController extends BaseController
{
    @Autowired
    private ITbActivityConfigService tbActivityConfigService;

    /**
     * 查询活动设置列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-activity:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbActivityConfig tbActivityConfig)
    {
        startPage();
        List<TbActivityConfig> list = tbActivityConfigService.selectTbActivityConfigList(tbActivityConfig);
        return getDataTable(list);
    }

    /**
     * 导出活动设置列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-activity:config:export')")
    @Log(title = "活动设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbActivityConfig tbActivityConfig)
    {
        List<TbActivityConfig> list = tbActivityConfigService.selectTbActivityConfigList(tbActivityConfig);
        ExcelUtil<TbActivityConfig> util = new ExcelUtil<TbActivityConfig>(TbActivityConfig.class);
        util.exportExcel(response, list, "活动设置数据");
    }

    /**
     * 获取活动设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-activity:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbActivityConfigService.selectTbActivityConfigById(id));
    }

    /**
     * 新增活动设置
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-activity:config:add')")
    @Log(title = "活动设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbActivityConfig tbActivityConfig)
    {
        return toAjax(tbActivityConfigService.insertTbActivityConfig(tbActivityConfig));
    }

    /**
     * 修改活动设置
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-activity:config:edit')")
    @Log(title = "活动设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbActivityConfig tbActivityConfig)
    {
        return toAjax(tbActivityConfigService.updateTbActivityConfig(tbActivityConfig));
    }

    /**
     * 删除活动设置
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-activity:config:remove')")
    @Log(title = "活动设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbActivityConfigService.deleteTbActivityConfigByIds(ids));
    }

    @Anonymous
    @GetMapping("/infoList")
    @ApiOperation("获取系统设置")
    public AjaxResult infoList() {
        List<TbActivityConfig> tbActivityConfigs = tbActivityConfigService.selectTbActivityConfigList(null);
        return AjaxResult.success(tbActivityConfigs);
    }
}
